//
//  DiaryViewController.m
//  kuimi
//
//  Created by guozhou-MAC001 on 15/9/14.
//  Copyright (c) 2015年 guozhou-MAC001. All rights reserved.
//

#import "DiaryViewController.h"
#import "DiaryTableViewCell.h"
#import "MJRefresh.h"
#import "MenuItem.h"
#import "PopMenu.h"
#import "oneDayViewController.h"
@interface DiaryViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *MYtable;
@property (nonatomic, strong) PopMenu *popMenu;
@end

@implementation DiaryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [_MYtable registerNib:[UINib nibWithNibName:@"DiaryTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    self.MYtable.estimatedRowHeight = 44.0f;
    self.MYtable.rowHeight = UITableViewAutomaticDimension;
    
    // Do any additional setup after loading the view from its nib.
    
    [self addNewDiary];
    [self addmj];
   
    
}
#pragma 添加刷新控件

-(void)addmj
{
    [self.MYtable addGifHeaderWithRefreshingBlock:^{
        [self.MYtable.header endRefreshing];
    }];
    
    // 隐藏时间
    self.MYtable.header.updatedTimeHidden = YES;
    
    // 隐藏状态
    self.MYtable.header.stateHidden = YES;
    
    // 设置普通状态的动画图片
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=60; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"dropdown_anim__000%zd", i]];
        [idleImages addObject:image];
    }
    [self.MYtable.gifHeader setImages:idleImages forState:MJRefreshHeaderStateIdle];
    
    // 设置正在刷新状态的动画图片
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=3; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"dropdown_loading_0%zd", i]];
        [refreshingImages addObject:image];
    }
    [self.MYtable.gifHeader setImages:refreshingImages forState:MJRefreshHeaderStateRefreshing];
    
    // 马上进入刷新状态
    [self.MYtable.header beginRefreshing];
}

#pragma 添加按钮
-(void)addNewDiary{
    UIButton *rightB = [UIButton buttonWithType:UIButtonTypeSystem];
    rightB.frame = CGRectMake(0, 0, 32, 32);
    [rightB setBackgroundImage:[UIImage imageNamed:@"add_narbar"] forState:UIControlStateNormal];
    [rightB addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightB];
    self.navigationItem.rightBarButtonItem = rightBar;
}
-(void)click{
    
    [self showMenu];
//    弹出心情选项
    NSLog(@"111");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma 表格
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DiaryTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.dateView.layer.cornerRadius=12.0f;
cell.cardView.layer.cornerRadius=8.0f;
    cell.backgroundColor=[UIColor clearColor];
   
    
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    oneDayViewController *oneview=[oneDayViewController new];
    [self.navigationController pushViewController:oneview animated:YES];
}
#pragma 选择心情

- (void)showMenu {
    NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:3];
    
    MenuItem *menuItem = [MenuItem itemWithTitle:@"烦心" iconName:@"fanxin"];
    [items addObject:menuItem];
    
    menuItem = [MenuItem itemWithTitle:@"焦急" iconName:@"jiaoji" ];
    [items addObject:menuItem];
    
    menuItem = [MenuItem itemWithTitle:@"难过" iconName:@"nanguo" ];
    [items addObject:menuItem];
    
    menuItem = [MenuItem itemWithTitle:@"平常" iconName:@"pingdan" ];
    [items addObject:menuItem];
    
    menuItem = [MenuItem itemWithTitle:@"幸运" iconName:@"xingyun" ];
    [items addObject:menuItem];
    
    menuItem = [MenuItem itemWithTitle:@"高兴" iconName:@"gaoxing"];
    [items addObject:menuItem];
    
    if (!_popMenu) {
        _popMenu = [[PopMenu alloc] initWithFrame:self.view.bounds items:items];
        _popMenu.menuAnimationType = kPopMenuAnimationTypeNetEase;
    }
    if (_popMenu.isShowed) {
        return;
    }
    _popMenu.didSelectedItemCompletion = ^(MenuItem *selectedItem) {
        NSLog(@"%@",selectedItem.title);
        oneDayViewController *onedayview=[oneDayViewController new];
        [self.navigationController pushViewController:onedayview animated:YES];
    };
    
    [_popMenu showMenuAtView:self.view];
    
    //    [_popMenu showMenuAtView:self.view startPoint:CGPointMake(CGRectGetWidth(self.view.bounds) - 60, CGRectGetHeight(self.view.bounds)) endPoint:CGPointMake(60, CGRectGetHeight(self.view.bounds))];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
